package com.customers.util;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import javax.servlet.ServletContextEvent;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Iterator;
import java.util.List;
import java.util.ResourceBundle;

public class ConnectJDBC {

    private static Connection connection = null;
    private static Element sqlelement;

    public static void setSqlelement(Element sqlelement) {
        ConnectJDBC.sqlelement = sqlelement;
    }

    public static void setConnection(ServletContextEvent sec){
       connection = (Connection) sec.getServletContext().getAttribute("jdbc");
    }

    public static Connection getConnection() {
        return connection;
    }

    public static PreparedStatement connectDB(String sql) {


        PreparedStatement statement = null;
        try {
//            ServletContext sct= getServletConfig().getServletContext();
            statement = connection.prepareStatement(sql);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return statement;
    }

    public static Element getsqlElement() {
        return sqlelement;
    }
}
